// pages/indexAll/list_message/list_message.js
const app = getApp()
var self;
var nowpage = 1;
var loginid;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    x: 0,
    y: 0,
    msglist:[]
  },
  tap: function (e) {
    this.setData({
      x: 30,
      y: 30
    });
  },
  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
       self = this;
       loginid = wx.getStorageSync('user') == "" ? -999 : wx.getStorageSync('user').UserID;
       if(loginid==-999){
         wx.navigateTo({
           url: '/pages/login/login',
         })
       }
  },
  getMessageList:function(){
    wx.request({
      url: app.globalData.apiUrl + "IS04/HIS040100.ashx?Method=GetXiaoXiList",
      data: {
        LoginID: loginid,
        rows:8,
        page:nowpage
      },
      method: 'GET',
      success: function (res) {
        
        if (res.data.state == 1) {
          var tmplist = self.data.msglist;
          var msglist = res.data.retData.XiaoXiList;
          if(msglist.length>0){
            nowpage++;
            for(var i=0;i<msglist.length;i++){
              msglist[i].FaSongShiJian = msglist[i].FaSongShiJian.replace(/\//g, '-');
              msglist[i].FaSongShiJian = msglist[i].FaSongShiJian.substring(0, msglist[i].FaSongShiJian.length - 3);
              tmplist.push(msglist[i]);
            }
            self.setData({
              msglist: tmplist
            })
          } else {
            wx.showToast({
              title: '没有更多数据',
              icon: 'none'
            })
          }
          
        }
      }
    });
  },
  setRead:function(e){
    
    var id = e.currentTarget.dataset.id;
    wx.request({
      url: app.globalData.apiUrl + "IS04/HIS040100.ashx?Method=SetXiaoXiYiDu",
      data: {
        LoginID: loginid,
        XiTongXiaoXiID:id
      },
      method: 'GET',
      success: function (res) {
        if (res.data.state == 1) {
          var tmplist = self.data.msglist;
          for(var i=0;i<tmplist.length;i++){
            if (tmplist[i].XiTongXiaoXiID==id||id==-999){
               tmplist[i].IsYiDu =1; 
            }
          }
          self.setData({
            msglist: tmplist
          })
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    loginid = wx.getStorageSync('user') == "" ? -999 : wx.getStorageSync('user').UserID;
     nowpage =1;
     self.getMessageList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    self.getMessageList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})